package com.xuan_poi.easyUtil;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.xuan_poi.easy.Student;
import org.apache.commons.io.FilenameUtils;
import org.junit.Test;

import java.io.File;
import java.util.*;

/**
 * @author renzhengxuan
 * @date 2021/4/14
 */
public class TestExcel {
    @Test
    public void testExcel() {
        String PATH = "D:\\excel\\bb.xls";
        File file = new File(PATH);
        String extension = FilenameUtils.getExtension(PATH);
        List<Student> students = ExcelUtil.imporeExcel(file, Student.class);
        if (students.size() > 0) {
            students.forEach(student -> {
                System.out.println(student);
            });
        }

    }

    @Test
    public List<Student> testImexcel() {
        List<Student> list = new ArrayList<>();
        File file = new File("");
        EasyExcel.read(file).head(Student.class).sheet()
                .registerReadListener(new AnalysisEventListener<Student>() {
                    @Override
                    public void invoke(Student student, AnalysisContext analysisContext) {
                        list.add(student);
                    }

                    @Override
                    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

                    }
                }).doRead();
        return list;
    }
    @Test
    public void write(){
        List<Student> list=new ArrayList<>();
        EasyExcel.write("",Student.class).sheet().doWrite(list);
    }
}
